#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
    int strToInt(string str) {
        int flag = 1;
        long long num = 0;
        int i = 0;
        while (i < static_cast<int>(str.size()))
        {
            if (str[i] != ' ')
                break;
            ++i;
        }
        if (i == static_cast<int>(str.size()))
            return 0;
        if (str[i] != '-' && str[i] != '+' && (str[i] < '0' && str[i] > '9'))
            return 0;
        else if (str[i] == '-')
        {
            flag = -1;
            ++i;
        }
        else if (str[i] == '+')
            ++i;
        while (str[i] >= '0' && str[i] <= '9')
        {
            num = num * 10 + (str[i] - '0');
            if (num >= INT_MAX && flag == 1)
                return INT_MAX;
            else if (num * (-1) <= INT_MIN && flag == -1)
                return INT_MIN;
            ++i;
        }
        return static_cast<int>(num * flag);
    }
};
int main()
{
    string str("-9999");
    cout << Solution().strToInt(str) << endl;
    return 0;
}